import router from 'koa-router';
import TileUtil4326 from '../lib/TileTool/TileUtil4326';
import TileUtil3857 from '../lib/TileTool/TileUtil3857';

const TileRoutes = new router({prefix: '/TileServer'});


const tileUtil3857 = new TileUtil3857();
const tileUtil4326 = new TileUtil4326();

// 通配符的写法
TileRoutes
    .all('/getTilesByGeoJson', async (ctx: any) => {
        ctx.set('Content-Type', 'application/json;charset=utf-8');
        const {
            token,
            tileSchema,
            level,
            dataSourceName,
            dataSourceToken,
            targetDirectory,
            geoJson
        } = ctx.request.body;

        const tileUtil = tileSchema === 'layer-xyz-3857' ? tileUtil3857 : tileUtil4326

        const tileList = tileUtil.getTilesByGeoJson(geoJson, level)


        ctx.body = JSON.stringify({
            code: 200,
            message: '瓦片分析成功',
            data: tileList
        });
        ctx.status = 200;
    })
;


export default TileRoutes;
